use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use chrono::{DateTime, Utc};

#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct User {
    pub id: i32,
    pub username: String,
    pub password: String,
    pub role: String,
    pub created_at: DateTime<Utc>,
}

#[derive(Debug, Deserialize)]
pub struct UserCreateRequest {
    pub username: String,
    pub password: String,
}

#[derive(Debug, Deserialize)]
pub struct LoginRequest {
    pub username: String,
    pub password: String,
}

#[derive(Debug, Serialize)]
pub struct LoginResponse {
    pub token: String,
    pub user: UserInfo,
}

#[derive(Debug, Serialize)]
pub struct UserInfo {
    pub id: i32,
    pub username: String,
    pub role: String,
}

//商品信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Commodity {
    pub id: i32,
    pub name: String,
    pub barcode: String,
    pub category: String,
    pub price: f64,
    pub purchase_price: f64,
    pub state: String,
}

#[derive(Debug, Deserialize)]
pub struct CommodityCreateRequest {
    pub name: String,
    pub barcode: String,
    pub category: String,
    pub price: f64,
    pub purchase_price: f64,
    pub state: String,
}

#[derive(Debug, Deserialize)]
pub struct CommodityDeleteRequest {
    pub id: i32,
}


//接班信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Handover {
    pub id: i32,
    pub date: DateTime<Utc>,
    pub handover: String,
    pub succession: String,
    pub amount: f64,
    pub total_amount: f64,
    pub notes: String,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct HandoverCreateRequest {
    pub date: DateTime<Utc>,
    pub succession: String,
    pub amount: f64,
    pub notes: String,
}

// #[derive(Debug, Deserialize)]
// pub struct HandoverDeleteRequest {
//     pub id: i32,
// }


//会员信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Member {
    pub id: i32,
    pub name: String,
    pub tel: String,
    pub date: DateTime<Utc>,
    pub expiration_date: DateTime<Utc>,
    pub state: String,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct MemberCreateRequest {
    pub name: String,
    pub tel: String,
    pub date: DateTime<Utc>,
    pub state: String,
}

#[derive(Debug, Deserialize)]
pub struct MemberDeleteRequest {
    pub id: i32,
}



//购货计划信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Plan {
    pub id: i32,
    pub name: String,
    pub amount: i32,
    pub state: String,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct PlanCreateRequest {
    pub name: String,
    pub amount: i32,
    pub state: String,
}

#[derive(Debug, Deserialize)]
pub struct PlanDeleteRequest {
    pub id: i32,
}





//销售信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Sale {
    pub id: i32,
    pub name: String,
    pub amount: i32,
    pub total_price: f64,
    pub cashier: String,
    pub date: DateTime<Utc>,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct SaleCreateRequest {
    pub name: String,
    pub amount: i32,
    pub date: DateTime<Utc>,
}

#[derive(Debug, Deserialize)]
pub struct SaleDeleteRequest {
    pub id: i32,
}


//销售统计信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct SaleStatistics {
    pub id: i32,
    pub date: DateTime<Utc>,
    pub price: f64,
    pub amount: i32,
    pub commodity_amount: i32,
    pub margin: f64,
}

#[derive(Debug, Deserialize)]
pub struct SaleStatisticsCreateRequest {
    pub date: DateTime<Utc>,
    pub price: f64,
    pub amount: i32,
    pub commodity_amount: i32,
}

#[derive(Debug, Deserialize)]
pub struct SaleStatisticsDeleteRequest {
    pub id: i32,
}




//存货记录信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Store {
    pub id: i32,
    pub name: String,
    pub amount: i32,
    pub price: f64,
    pub date: DateTime<Utc>,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct StoreCreateRequest {
    pub name: String,
    pub amount: i32,
    pub price: f64,
    pub date: DateTime<Utc>,
}

#[derive(Debug, Deserialize)]
pub struct StoreDeleteRequest {
    pub id: i32,
}

//存货信息
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Stored {
    pub commodity_id: i32,
    pub name: String,
    pub amount: i32,
    pub state: String,
    pub operation: String,
}

#[derive(Debug, Deserialize)]
pub struct StoredCreateRequest {
    pub name: String,
    pub amount: i32,
}
#[derive(Debug, Deserialize)]
pub struct StoredUpdateRequest {
    pub name: String,
    pub change_amount: i32,
}

#[derive(Debug, Deserialize)]
pub struct StoredDeleteRequest {
    pub id: i32,
}